package com.gai.shop.service.impl;

import com.gai.shop.dao.TypeDao;
import com.gai.shop.dao.impl.TypeDaoImpl;
import com.gai.shop.entity.Type;
import com.gai.shop.service.TypeService;
import com.gai.shop.util.StrUtils;

import java.util.List;

public class TypeServiceImpl implements TypeService {
    private final TypeDao TD = new TypeDaoImpl();

    /**
     * 查询
     * @return List<Type>
     */
    @Override
    public List<Type> selectTypeAll() {
        List<Type> typeList = null;
        try {
            typeList = TD.selectTypeAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return typeList;
    }

    /**
     * 动态查询
     * @param tname
     * @return
     */
    @Override
    public List<Type> getAllByKey(String tname) {
        List<Type> typeList = null;
        try {//这里不能去判断tname是否为null空 他是个动态查询，所有参数是可以为null的
            typeList = TD.getAllByKey(tname);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return typeList;
    }

    /**
     * 新增商品
     * @param tname
     * @param tinfo
     * @return
     */
    @Override
    public Integer addType(String tname, String tinfo) {
        Integer result = 0;
        try {
            if (StrUtils.empty(tname,tinfo)) {
                result = TD.addType(tname, tinfo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
